<template>
	<view class="app-container">
		<image class="header-image" src="@/static/image/login/bg1.png"></image>
		<view class="login-wrap">
			<view class="login-title">登 录</view>
			<form class="login-form">
				<view class="login-form-item">
					<text class="iconfont icon-username"></text>
					<input type="text" name="phone" placeholder="请输入手机号码" maxlength="11" v-model="loginForm.username" />
				</view>
				<view class="login-form-item">
					<text class="iconfont icon-password"></text>
					<input type="password" name="password" placeholder="请输入手机号码" maxlength="32" v-model="loginForm.password" />
				</view>
				<view class="login-form-forget" @click="$utils.jumpTo('/pages/public/forget')">忘记密码</view>
				<button type="default" @click="handleUserLogin">登 录</button>
			</form>
		</view>
		<view class="register-card">
			<view>
				还没有登录账号？
				<text class="text">立刻注册</text>
			</view>
		</view>
		<image class="footer-image" src="@/static/image/login/bg2.png"></image>
	</view>
</template>

<script>
	import { login } from '@/api/public'
	import { setToken } from '@/utils/auth'
	
	export default {
		data() {
			return {
				loginForm: {}
			}
		},
		create() {
			this.initData()
		},
		methods: {
			// 初始化
			initData() {},
			// 登录
			handleUserLogin() {
				this.$utils.loading('加载中')
				login(this.loginForm).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						setToken(res.data.token)
						this.$store.commit('SET_USERINFO', res.data)
						this.$utils.msg(res.message, 1500, false, 'success')
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.app-container {
	height: 100vh;
	background: linear-gradient(to bottom, #ff6a9a, #fe7d76);
}
.header-image {
	width: 100%;
}
.login-wrap {
	position: relative;
	z-index: 9;
	width: 690rpx;
	padding: 55rpx;
	margin: 0 auto;
	margin-top: -200rpx;
	font-size: 28rpx;
	background-color: #ffffff;
	border-radius: 20rpx;
	box-shadow: 0 5px 7px 0 rgba(0, 0, 0, 0.15);
	
	.login-title {
		margin: 0 0 50rpx 20rpx;
		color: #ff939b;
		font-size: 46rpx;
		font-weight: bold;
		text-align: left;
	}
	.login-form {
		zoom: 1;
		
		.login-form-item {
			position: relative;
			
			.iconfont {
				position: absolute;
				left: 40rpx;
				top: 28rpx;
				width: 40rpx;
				height: 40rpx;
				padding-right: 20rpx;
			}
		}
		.login-form-forget {
			margin: -20rpx 30rpx 40rpx 0;
			color: #c0c0c0;
			text-align: right;
		}
		input {
			margin-bottom: 50rpx;
			padding: 0 20rpx 0 120rpx;
			height: 90rpx;
			line-height: 90rpx;
			font-size: 28rpx;
			background: #f6f6f6;
			border: 1px solid #f6f6f6;
			border-radius: 50rpx;
		}
		button {
			height: 90rpx;
			line-height: 90rpx;
			color: #fff;
			font-size: 28rpx;
			background: linear-gradient(to right, #ff8f77, #fe519f);
			border-radius: 50rpx;
		}
	}
	.login-form:after {
		content: '\20';
		display: block;
		clear: both;
		height: 0;
		visibility: hidden;
	}
}
.register-card {
	position: relative;
	flex-direction: row;
	align-items: center;
	width: 600rpx;
	height: 80rpx;
	margin: 0 auto;
	padding: 5px;
	text-align: center;
	line-height: 70rpx;
	color: #aaa;
	font-size: 28rpx;
	background: #fff;
	border-radius: 0 0 20rpx 20rpx;
	opacity: 0.9;
	
	.text {
		color: #fe519f;
	}
}
.footer-image {
	position: absolute;
	bottom: 0;
	width: 100%;
	height: 45px;
}
</style>
